// pages/user/team/invite.js
import painter from '../../../utils/painterImage/image'

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    template: {},
    shareImage: '',
  },

  //获取二维码接口
  getQr(){
    let _this = this;
    let user = app.getUser();

    let path = 'sub/user/shop-ask/shop-ask';
    app.requestUrl({
      method: 'POST',
      url: '/wxapi/qr/appCode',
      data: {
        flag: 1,
        url: path,
        upShopId: '',
        upCentreId: '',
        goodsId: '',
        centreId: user.centreId,
        cd: user.myCode,
        userId: user.id,
      },
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
        'Authorization': wx.getStorageSync('authToken') || 'empty-token'
      },
    }).then(res =>{
      let tempQr = res.data.date;
      console.log(user.avatar)
      _this.setData({
        template: new painter().shopShare2('https://o.rjkj7.com/data/upload/xcximages/qr_back_1.png','https://o.rjkj7.com/data/upload/xcximages/qr_back_2.png',user.nickname,user.avatar,tempQr),
      })
    })
  },

  onImgOK(e) {
    this.setData({
      shareImage: e.detail.path
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getQr();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const user = app.getUser();
    let name = user.realname || user.nickname
    let url = '/sub/user/shop-ask/shop-ask?code=' + user.myCode + '&upname=' + name + '&upcentreid=' + user.centreId
    return {
      title: name + '诚邀您为仁捷科技服务平台店主，高薪店主，月入过万，一份真正钱多、事少、离家近的自由事业',
      path: url
    }
  }
})